package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqupt.cxcy.dao.AdminDao;
import cn.edu.cqupt.cxcy.dto.AdminImpl;


/**
 * 主页-【场地预约】
 * @author Dancer-mno
 * @date 2015年10月17日
 */
@SuppressWarnings("serial")
public class AdminAjaxAddLable extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String html  = req.getParameter("type"); //页面
		String lable = req.getParameter("lable"); //标签
		AdminDao admin = new AdminImpl();
		boolean flag = false;
		// /admin/addLable 返回是否成功,true为成功
		//场地类型  	 admin/addLable?&&type=cdyy&&lable=?
		//新闻类型 	 admin/addLable?&&type=news&&lable=?
		//导师辅导类型     admin/addLable?&&type=teac&&lable=?
		//项目类型             admin/addLable?&&type=pros&&lable=?

		if("cdyy".equals(html)) {
			if(!admin.isHaveLable_Cdyy(lable)) {
				synchronized (this) {
					flag = admin.addLable_Cdyy(lable);
				}
			} 
		} else if("news".equals(html)) {
			if(!admin.isHaveLable_News(lable)) {
				synchronized (this) {
					flag = admin.addLable_News(lable);
				}
			} 
		} else if("teac".equals(html)) {
			if(!admin.isHaveLable_Teac(lable)) {
				synchronized (this) {
					flag = admin.addLable_Teac(lable);
				}
			} 
		} else if("pros".equals(html)) {
			if(!admin.isHaveLable_Pros(lable)) {
				synchronized (this) {
					flag = admin.addLable_Pros(lable);
				}
			} 
		}
		resp.setContentType("application/json;charset=utf-8");
		resp.setHeader("pragma","no-cache");
		resp.setHeader("cache-control","no-cache");
		PrintWriter out = resp.getWriter();
		out.print(flag);
		out.flush();
		out.close();
	}


}
